package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MesNeedMapper;
import com.ruoyi.system.domain.MesNeed;
import com.ruoyi.system.service.IMesNeedService;

/**
 * 物料需求单Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-01
 */
@Service
public class MesNeedServiceImpl implements IMesNeedService 
{
    @Autowired
    private MesNeedMapper mesNeedMapper;

    /**
     * 查询物料需求单
     * 
     * @param id 物料需求单主键
     * @return 物料需求单
     */
    @Override
    public MesNeed selectMesNeedById(Integer id)
    {
        return mesNeedMapper.selectMesNeedById(id);
    }

    /**
     * 查询物料需求单列表
     * 
     * @param mesNeed 物料需求单
     * @return 物料需求单
     */
    @Override
    public List<MesNeed> selectMesNeedList(MesNeed mesNeed)
    {
        return mesNeedMapper.selectMesNeedList(mesNeed);
    }

    /**
     * 新增物料需求单
     * 
     * @param mesNeed 物料需求单
     * @return 结果
     */
    @Override
    public int insertMesNeed(MesNeed mesNeed)
    {
        return mesNeedMapper.insertMesNeed(mesNeed);
    }

    /**
     * 修改物料需求单
     * 
     * @param mesNeed 物料需求单
     * @return 结果
     */
    @Override
    public int updateMesNeed(MesNeed mesNeed)
    {
        return mesNeedMapper.updateMesNeed(mesNeed);
    }

    /**
     * 批量删除物料需求单
     * 
     * @param ids 需要删除的物料需求单主键
     * @return 结果
     */
    @Override
    public int deleteMesNeedByIds(Integer[] ids)
    {
        return mesNeedMapper.deleteMesNeedByIds(ids);
    }

    /**
     * 删除物料需求单信息
     * 
     * @param id 物料需求单主键
     * @return 结果
     */
    @Override
    public int deleteMesNeedById(Integer id)
    {
        return mesNeedMapper.deleteMesNeedById(id);
    }

    @Override
    public boolean isNeedIdUnique(MesNeed mesNeed, Boolean addOrUpdate)
    {
        int count = mesNeedMapper.countByNeedId(mesNeed.getNeedId());
        if(addOrUpdate) {
            return count == 0;
        }
        else {
            if(mesNeed.getNeedId().equals(mesNeed.getOldNeedId())){
                return count == 1;
            }
            else {
                return count == 0;
            }
        }
    }
}
